import DB_CURD


## 数据查询
def query_main():
    q_name = '用户001'
    q_sql = f"select * from user_info where id = 1 and name='{q_name}'"
    print(q_sql)
    result = DB_CURD.db_query(q_sql)
    if len(result):
        for row in result:
            print(row)


## 数据删除
def delete_main():
    d_sql = f"delete from user_info where id = 2 "
    print(d_sql)
    result = DB_CURD.db_delete(d_sql)
    print(f'受影响的行数：{result}')


## 数据更新
def update_main():
    u_sql = f"update user_info set age=50 where id = 3 "
    print(u_sql)
    result = DB_CURD.db_update(u_sql)
    print(f'受影响的行数：{result}')


## 数据插入
def insert_main():
    i_sql = f" insert into user_info(name,email,gender,age,phone,password) values (%s,%s,%s,%s,%s,%s) "
    data = [
        ('李白', 'libai@qq.com', 0, 20, 13382656301, '1fdsf2dfki3hija9shkasdifj'),
        ('妲己', 'daji@qq.com', 0, 20, 13382656302, '1fdsf2dfki3hija9shkasdifj'),
        ('夏侯惇', 'xiahoudun@qq.com', 0, 20, 13382656303, '1fdsf2dfki3hija9shkasdifj'),
        ('廉颇', 'lianpo@qq.com', 0, 20, 13382656304, '1fdsf2dfki3hija9shkasdifj'),
        ('后羿', 'houyi@qq.com', 0, 20, 13382656305, '1fdsf2dfki3hija9shkasdifj'),
        ('兰陵王', 'lanlingwang@qq.com', 0, 20, 13382656306, '1fdsf2dfki3hija9shkasdifj'),
        ('小乔', 'xiaoqiao@qq.com', 0, 20, 13382656307, '1fdsf2dfki3hija9shkasdifj'),
        ('李信', 'lixin@qq.com', 0, 20, 13382656308, '1fdsf2dfki3hija9shkasdifj'),
        ('牛魔', 'niumo@qq.com', 0, 20, 13382656309, '1fdsf2dfki3hija9shkasdifj'),
        ('黄忠', 'huangzhong@qq.com', 0, 20, 13382656310, '1fdsf2dfki3hija9shkasdifj')
    ]
    result = DB_CURD.db_insert(i_sql, data)
    print(f'受影响的行数：{result}')


if __name__ == '__main__':
    insert_main()
